const fs=require('fs');
class FsUtil {
  constructor() {
    
  }
  static open(path) {
    return new Promise((resolve,reject) => {
        fs.open(path, 'w+', function(err, fd) {
            if (err) {
                reject(err);
            }
            resolve(fd);    
        });
    });
  }
  static close(fd) {
    return new Promise((resolve,reject) => {
        fs.close(fd, function(err){
            if (err) {
                reject(err);
            }
            resolve("文件关闭成功");
        });
    });
  }
  static remove(path) {
    return new Promise((resolve,reject) => {
        fs.unlink(path, function(err){
            if (err) {
                reject(err);
            }
            resolve("文件删除成功");
        });
    });
  }
  static rename(oldPath,newPath) {
    return new Promise((resolve,reject) => {
        fs.rename(oldPath, newPath,  function(err){
            if (err) {
                reject(err);
            }
            resolve("文件改名成功");
        });
    });
  }
  static copyFile(oldPath,newPath) {
    return new Promise((resolve,reject) => {
        fs.copyFile(oldPath, newPath,  function(err){
            if (err) {
                reject(err);
            }
            resolve("文件复制成功");
        });
    });
  }


}
module.exports =  FsUtil;